package com.sali.config;

import com.sali.handler.ProtocolModelHandle;
import com.sali.handler.ProtocolModelLoad;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.File;
import java.io.FileNotFoundException;

/**
 * @description: 加载模型文件
 * @author: sali
 * @date: 2024/7/16 20:49.
 * @version: 1.0
 */
@Configuration
@ConfigurationProperties(prefix = "common.file-read")
@Slf4j
@Data
public class FileReaderConfig {

    private String metaDataPath;


    @Bean
    public ProtocolModelHandle getProtocolModelHandle() {
        //加载model文件
        String modelFilePath = metaDataPath + File.separator + "sali-ods-model.xlsx";
        //初始化ProtocolModelHandle
        ProtocolModelLoad protocolModelLoad = ProtocolModelLoad.createBuilder().build();
        ProtocolModelHandle protocolModelHandle = ProtocolModelHandle.createBuilder().protocolModelLoad(protocolModelLoad).build();
        try {
            protocolModelHandle.init(modelFilePath);
            return protocolModelHandle;
        } catch (FileNotFoundException e) {
            log.error("Model load failed ，modelFilePath：{}", modelFilePath, e);
        }
        return null;
    }

}
